import request from '@/utils/request';

export interface PapersItem {
  _id: number;
  paperName: string;
  paperContent: string;
  categories: string;
  rules: string;
  isOpen: string;
}

export function getPapers(params = {}) {
  return request({
    url: '/papers',
    method: 'post',
    data: params
  });
}

export function addPaper(params: any = {}) {
  const { paperContent, rules, ...rest } = params;
  const data = {
    ...rest,
    paperContent: paperContent ? JSON.stringify(paperContent) : null,
    rules: rules ? JSON.stringify(rules) : null,
    isOpen: '否'
  };
  return request({
    url: '/addPaper',
    method: 'post',
    data
  });
}

export function updatePaperStatus(params: any = {}) {
  return request({
    url: '/updatePaperStatus',
    method: 'post',
    data: params
  });
}

export function searPaperContent(ids: string[] = []) {
  return request({
    url: '/getPaperContent',
    method: 'post',
    data: {
      ids
    }
  });
}

export function delPaper(params = {}) {
  return request({
    url: '/delPaper',
    method: 'post',
    data: params
  });
}

export function updatePapers(params = {}) {
  return request({
    url: '/updateQuestion',
    method: 'post',
    data: params
  });
}

export function uploadpapers(params = {}) {
  return request({
    url: '/uploadPapers',
    method: 'post',
    data: params
  });
}
